<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>第二周/03/练习1.html</title>
  </head>
  <body></body>
  <script>
    /**
     * 计算100-1000的水仙花数
     */
    for (i = 100; i < 1000; i++) {
      var array = Array.from(String(i), Number);
      if (array[0] ** 3 + array[1] ** 3 + array[2] ** 3 == i) {
        console.log(i);
      }
    }

    /**
     * 计算出斐波那契数列第20位
     */
    var array1 = new Array();
    array1[0] = 1;
    array1[1] = 1;
    for (i = 2; i < 20; i++) {
      array1[i] = array1[i - 1] + array1[i - 2];
      console.log(array1[i]);
    }
    /**
     * 选择排序
     */
    function xuanpai(array) {
      for (i = 0; i < array.length; i++) {
        var min = array[i];
        var min_arr = i;
        for (j = i + 1; j < array.length; j++) {
          if (min > array[j]) {
            min = array[j];
            min_arr = j;
          }
        }
        var temp = array[i];
        array[i] = array[min_arr];
        array[min_arr] = temp;
      }
    }
    /**
     * 冒泡排序
     */
    var array2 = [2, 7, 55, 12, 5, 9, 10];
    xuanpai(array2);
    console.log(array2);

    function maopai(array) {
      for (i = 0; i < array.length; i++) {
        for (j = 0; j < array.length - i - 1; j++) {
          if (array[j] > array[j + 1]) {
            var temp = array[j];
            array[j] = array[j + 1];
            array[j + 1] = temp;
          }
        }
      }
    }
    var array3 = [100, 7, 55, 12, 5, 9, 10];
    maopai(array3);
    console.log(array3);
    /**
     * 鸡免同笼:总共100个脚，各多少只?列出所有可能性。
     */
    function jitu(a) {
      for (i = 1; i <= a / 4; i++) {
        console.log(i + "只兔");
        var b = (100 - i * 4) / 2;
        console.log(b + "只鸡");
      }
    }
    console.log(jitu(100));
  </script>
</html>
